import 'package:flutter/material.dart';
import 'package:ge_app/model/index_now_model.dart';
import 'package:dio/dio.dart';
import 'dart:convert';

class SecondPage extends StatefulWidget {
  @override
  _SecondPageState createState() => _SecondPageState('', '', '', '');
}

class _SecondPageState extends State<SecondPage> {

//  List<IndexNowModel> indexNowList = [];
  String name;
  String price;
  String date;
  String time;


  _SecondPageState(this.price, this.name, this.date, this.time);

//  String data = '';
//  Map indexNowMap = jsonDecode(data);
  //      var data = jsonDecode(response.toString());
//  var da;
  var varList = new IndexNowModel();
//  String SList;

  @override
  void initState() {
    super.initState();
    getHttp();
//    print(da);
  }

  void getHttp() async {
    try {
      print("111111111111111111111111111111");
//      print(_indexNow);
//      Response response = await Dio().get("https://www.07ge.com/api/stock_index?id=now_index");
      Response response = await Dio().get("https://www.07ge.com/geweb/stock_index/now_index");
//      var data = jsonDecode(response.toString());
      var data = response.toString();
      print(data);

      Map indexNowMap = jsonDecode(data);
      var indexList = new IndexNowModel.fromJson(indexNowMap);
      print('name, ${indexList.data[0].name}!');
//      setState(() {
//        indexNow = fromJson(response);
//      });
//      indexNowModel = response.data;

//      varList = indexList;
//      print(response is List);
//      print(varList);
//      print(varList is List);

//      data = response.data;
      print(indexList);
      print(indexList is Map);
      print(indexList is Object);
      print(indexList is String);
      print(indexList is Response);
      print(indexList is List);
//      print(data);
//      print(data.data is Map);
//      print(data.data);
      print("22222222222");
      print(varList.data);
      print(varList is Object);
      varList = indexList;
      print(varList);
      print(varList is Object);
      print('name, ${varList.data[0].name}!');
      setState(() {
        name = varList.data[0].name;
        price = varList.data[0].price;
        date = varList.data[0].date;
        time = varList.data[0].time;
      });
//      print(abc);

//      print(indexNowList);
//      print(data['data'][0]['name']);

//      print(indexNowModel);

//      return response.data;
      return response.data;
    } catch (e) {
      print(e);
    }

  }

  @override
  Widget build(BuildContext context) {
//    var addd = varList.data[0].name;
//    print(addd);
//    var addd = varList.code;
//    print(addd);
//    return Row(
//      children: <Widget>[
//        Text(addd.toString()),
//        Text(addd.toString()),
//        Text(addd.toString()),
//        Text(addd.toString()),
//      ],
//    );
    return
      MaterialApp(
//      title: 'ahahah',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: Scaffold(
          appBar: AppBar(
            title: Text('大盘指数'),
          ),
          body: new Container(
//              margin: EdgeInsets.all(10),
//            padding: EdgeInsets.all(50),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: <Widget>[

                  Container(
                          padding: EdgeInsets.all(50),
                          decoration: new BoxDecoration(
                          borderRadius: BorderRadius.circular(5.0),
                          border: new Border.all(//添加边框
                            width: 1.0,//边框宽度
                            color: Colors.grey,//边框颜色
                          )
                      ),
                    child: Column(
                      children: <Widget>[
                        Text(name),
                        Text(price),
                        Text(date),
                        Text(time),
                      ],
                    )
                  ),

                  Container(
                      padding: EdgeInsets.all(50),
                      decoration: new BoxDecoration(
                          borderRadius: BorderRadius.circular(5.0),
                          border: new Border.all(//添加边框
                            width: 1.0,//边框宽度
                            color: Colors.grey,//边框颜色
                          )
                      ),
                      child: Column(
                        children: <Widget>[
                          Text(name),
                          Text(price),
                          Text(date),
                          Text(time),
                        ],
                      )
                  )


                ],
              ),
//              child: Column(
//                children: <Widget>[
//                  Text(name),
//                  Text(name),
//                  Text(name),
//                  Text(name),
//                  Text(price),
//                  Text(date),
//                  Text(time),
//                  Padding(
//                    padding: EdgeInsets.all(200.0),
//                  ),
//        ],
//              )
          ),
        ),
      );

    }

}